﻿// <copyright file="ObjectHelper.cs" company="Joe Chung">
// Copyright © 2008 by Joe Chung.
// </copyright>
namespace NScheme
{
    using System;

    public static class ObjectHelper
    {
        public static bool? AsBoolean(object value)
        {
            try
            {
                return (bool)value;
            }
            catch (InvalidCastException)
            {
                return null;
            }
        }

        public static bool IsFalse(object value)
        {
            bool? x = AsBoolean(value);
            return x.HasValue && x.Value == false;
        }

        public static bool IsTrue(object value)
        {
            bool? x = AsBoolean(value);
            return x.HasValue && x.Value == true;
        }
    }
}